package top.wkq.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.wkq.middleware.dynamic.thread.pool.sdk.domain.DynamicThreadPoolService;
import top.wkq.middleware.dynamic.thread.pool.sdk.domain.model.entity.ThreadPoolConfigEntity;

import javax.annotation.Resource;

/**
 * @author 21129
 */
@RestController
@RequestMapping("test")
public class TestController {
    @Resource
    private DynamicThreadPoolService dynamicThreadPoolService;

    /**
     * 查看所有线程数
     */
    @RequestMapping("getThreadPoolConfigList")
    public Object getThreadPoolConfigList() {
        return dynamicThreadPoolService.getThreadPoolConfigList();
    }
    /**
     * 查看某个线程池配置
     */
    @RequestMapping("getThreadPoolConfigByName")
    public Object getThreadPoolConfigByName(String threadPoolName) {
        return dynamicThreadPoolService.getThreadPoolConfigByName(threadPoolName);
    }
    /**
     * 更新某个线程池配置
     */
    @RequestMapping("updateThreadPoolConfig")
    public Object updateThreadPoolConfig(String threadPoolName, Integer corePoolSize, Integer maximumPoolSize) {
        ThreadPoolConfigEntity threadPoolConfigByName = dynamicThreadPoolService.getThreadPoolConfigByName(threadPoolName);
        threadPoolConfigByName.setCorePoolSize(corePoolSize);
        threadPoolConfigByName.setMaximumPoolSize(maximumPoolSize);
        dynamicThreadPoolService.updateThreadPoolConfig(threadPoolConfigByName);
        return threadPoolConfigByName;
    }
}
